package com.zjw.xm.xmindex.web;

import com.zjw.xm.xmindex.web.feign.IOrderAction;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@RestController
public class IndexAction {

    @Resource
    IOrderAction iOrderAction;

    @GetMapping("/")
    ModelAndView index(ModelAndView mav ){
        mav.setViewName("index"); //请求转发
        mav.addObject("news",iOrderAction.queryNew());
        mav.addObject("cates",iOrderAction.queryCategory());
        mav.addObject("catesAndBooks",iOrderAction.selectCategory());
        return mav;
    }

    @GetMapping("/{page}.htm")
    ModelAndView toPage(@PathVariable String page, ModelAndView mav) {
        mav.setViewName(page);
        return mav;
    }

    @GetMapping("/book_{id}")
    ModelAndView book(@PathVariable int id, ModelAndView mav){
        mav.setViewName("book"); //请求转发
        mav.addObject("bookDetail",iOrderAction.findById(id));
        mav.addObject("cates",iOrderAction.queryCategory());
        return mav;
    }

    @RequestMapping("/books_xzts_{page}")
    ModelAndView toXztu(
            @PathVariable int page,
            @RequestParam(defaultValue = "5") int size,
            ModelAndView mav) {
            mav.setViewName("book_list");
            mav.addObject("catebook",iOrderAction.queryPageByPaking("线装",page,size));
            mav.addObject("type","xzts");


        return mav;
    }

    @RequestMapping("/books_lpts_{page}")
    ModelAndView toLpts(
            @PathVariable int page,
            @RequestParam(defaultValue = "5") int size,
            ModelAndView mav) {
        mav.setViewName("book_list");
        mav.addObject("catebook",iOrderAction.queryPageByPaking("精装",page,size));
        mav.addObject("type","lpts");
        return mav;
    }

    @RequestMapping("/books_dxwx_{page}")
    ModelAndView toDxwx(
            @PathVariable int page,
            @RequestParam(defaultValue = "5") int size,
            ModelAndView mav) {
        mav.setViewName("book_list");
        mav.addObject("catebook",iOrderAction.queryPageByDxwx(32,page,size));
        mav.addObject("type","dxwx");
        return mav;
    }

    @RequestMapping("/books_fznj_{page}")
    ModelAndView toFznj(
            @PathVariable int page,
            @RequestParam(defaultValue = "5") int size,
            ModelAndView mav) {
        mav.setViewName("book_list");
        mav.addObject("catebook",iOrderAction.queryPageByFznj(page,size));
        mav.addObject("type","fznj");
        return mav;
    }

    @GetMapping("/bookList_{id}")
    ModelAndView queryBookPages(
            @PathVariable int id,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "15") int size,
            ModelAndView mav) {
        mav.setViewName("bookList");
        mav.addObject("Lists",iOrderAction.queryBookPage(id,page,size));
        return mav;
    }




}
